package cn.yunhe.servlet;

import cn.yunhe.service.ProductService;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
@WebServlet("/deleteProductServlet")
public class DeleteProductServlet extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        int pid = Integer.parseInt(request.getParameter("pid"));
       String curpStr =  request.getParameter("curpage");
       int curpage = 1;
       if (curpStr!=null){
           curpage=Integer.parseInt(curpStr);
       }
       ProductService productService = new ProductService();
       boolean b =productService.delProByEpid(pid);
       request.setAttribute("pid",pid);
       request.setAttribute("curpage",curpage);
       if (b){
            request.getRequestDispatcher("/productListServlet").forward(request,response);
        }
    }

    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        doGet(request,response);
    }
}
